package com.info.zhiduoduo.admin.service;


import com.info.zhiduoduo.admin.model.formbean.invoice.InvoiceAmountFormBean;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.core.service.common.BaseService;
import com.info.zhiduoduo.repository.dto.invoice.InvoiceAmountDto;
import com.info.zhiduoduo.repository.mapper.invoice.InvoiceMapper;
import com.info.zhiduoduo.repository.mapper.taxer.TaxerInvoiceMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

@Service
public class InvoiceMonthAmountService extends BaseService {
    @Resource
    InvoiceMapper invoiceMapper;
    @Resource
    TaxerInvoiceMapper taxerInvoiceMapper;

    public SmartResult getInvoiceMakerAmount(BaseSimpleFormBean<InvoiceAmountFormBean> formBean) {
        Integer year = formBean.getReqdata().getYear();
        Calendar rightNow = Calendar.getInstance();
        int y = rightNow.get(Calendar.YEAR);
        ArrayList<Object> list = new ArrayList<>();
        List<InvoiceAmountDto> maker;
        List<InvoiceAmountDto> crowdsource;
        if (year == null || year == y) {
            maker = invoiceMapper.getInvoiceMakerAmount(1);
            crowdsource = invoiceMapper.getInvoiceMakerAmount(2);
        } else if (y < year) {
            maker = invoiceMapper.getInvoiceMakerAmountAfter(1, year);
            crowdsource = invoiceMapper.getInvoiceMakerAmountAfter(2, year);
        } else {
            maker = invoiceMapper.getInvoiceMakerAmountBefore(1, year);
            crowdsource = invoiceMapper.getInvoiceMakerAmountBefore(2, year);
        }
        if (year == null) {
            year = y;
        }
        List<InvoiceAmountDto> agentTaxer = taxerInvoiceMapper.getInvoiceTaxerAmount(year, 1);
        List<InvoiceAmountDto> taxer = taxerInvoiceMapper.getInvoiceTaxerAmount(year, 2);
        list.add(maker);
        list.add(crowdsource);
        list.add(agentTaxer);
        list.add(taxer);
        return smartResult(list);

    }

}
